<div class="bjui-pageHeader" style="background-color: #fff">
    <form data-toggle="ajaxsearch" class="search-form" id="form-search-attendance-statistics-list" data-options="{
        searchDatagrid:$.CurrentNavtab.find('#dg-attendance-statistics-list'),
        beforeSubmit:searchDgAttendanceStatisticsList,
            }">
        <fieldset>
            <legend style="font-weight:normal;">搜索：</legend>
            <div style="margin:0; padding:1px 5px 5px;" class="row">
                <div class="col-md-3">
                    <label class="row-label" >姓名:</label>
                    <input type="text" name="name" class="form-control" size="15" >
                </div>
                {{--<div class="col-md-3">--}}
                    {{--<label class="row-label" >时间:</label>--}}
                    {{--<input type="text" name="time" value="{{$time or ''}}" data-toggle="datepicker" data-pattern="yyyy-MM">--}}
                {{--</div>--}}
                <div class="col-md-3">
                    <label class="row-label" >开始时间:</label>
                    <input type="text" name="start_time" value="{{$start_time or ''}}" data-toggle="datepicker" data-pattern="yyyy-MM-dd" data-max-date="{{$max_time}}">
                </div>
                <div class="col-md-3">
                    <label class="row-label" >结束时间:</label>
                    <input type="text" name="end_time" value="{{$end_time or ''}}" data-toggle="datepicker" data-pattern="yyyy-MM-dd" data-max-date="{{$max_time}}">
                </div>
                <div class="btn-group">
                    <button type="submit" class="btn-blue" data-icon="search">搜索</button>
                    <button type="reset" class="btn-orange" data-icon="times">重置</button>
                </div>
            </div>
        </fieldset>
    </form>
    <p>迟到旷工次数:<span class="late-count" style="color: blue">{{$clock_in_late + $clock_in_absence}}</span></p>
    <p>早退次数:<span class="early-count" style="color: blue">{{$clock_out_early}}</span></p>
</div>
<div class="bjui-pageContent">
    <table id="dg-attendance-statistics-list" class="table table-bordered" data-toggle="datagrid" data-options="{
        height: '100%',
        dataUrl: '/admin/personnel/attendance/statistics-list',
        dataType:'json',
        sortAll: false,
        local: 'remote',
        fullGrid: true,
        postData:{
            start_time:'{{$start_time}}',
            end_time:'{{$end_time}}',
        },
        showEditbtnscol: false,
        fieldSortable: false,
        filterThead: false,
        columnMenu: false,
        showToolbar: false,
        toolbarCustom: toolbar,
    }">
        <thead>
        <tr>
            <th data-options="{name:'name', align:'center', width:100}">姓名</th>
            {{--<th data-options="{name:'clock_in_on_time', align:'center', width:100}">准时上班打卡</th>--}}
            {{--<th data-options="{name:'clock_in_late', align:'center', width:100}">迟到</th>--}}
            {{--<th data-options="{name:'clock_in_absence', align:'center', width:100}">旷工</th>--}}
            {{--<th data-options="{name:'clock_out_on_time', align:'center', width:100}">准时下班打卡</th>--}}
            {{--<th data-options="{name:'clock_out_early', align:'center', width:100}">早退</th>--}}
            <th data-options="{render:columnClockInOnTime, align:'center', width:100}">准时上班打卡</th>
            <th data-options="{render:columnClockInLate, align:'center', width:100}">迟到</th>
            <th data-options="{render:columnClockInAbsence, align:'center', width:100}">旷工迟到</th>
            <th data-options="{render:columnClockOutOnTime, align:'center', width:100}">准时下班打卡</th>
            <th data-options="{render:columnClockOutEarly, align:'center', width:100}">早退</th>
            <th data-options="{render:columnFieldCheckIn, align:'center', width:100}">外勤</th>
            <th data-options="{render:columnPatchCheckIn, align:'center', width:100}">补签</th>
            <th data-options="{render:columnLeaveTimes, align:'center', width:100}">请假</th>
            <th data-options="{render:columnBusinessTripTimes, align:'center', width:100}">出差</th>
            <th data-options="{render:columnOvertimeTimes, align:'center', width:100}">加班</th>
            <th data-options="{name:'missed_clock_in', align:'center', width:100}">早打卡漏打次数</th>
            <th data-options="{name:'missed_clock_out', align:'center', width:100}">晚打卡漏打次数</th>
            <th data-options="{name:'missed_check_in', align:'center', width:100}">漏打天数</th>
            <th data-options="{name:'should_work_days', align:'center', width:100}">应工作天数</th>
            <th data-options="{name:'should_not_work_days', align:'center', width:100}">应休假天数</th>
            {{--<th data-options="{align:'center', render:operationColumn, width:150}">操作</th>--}}
        </tr>
        </thead>
    </table>
</div>
<script>
    function columnClockInOnTime(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 1)">' + data.clock_in_on_time + '</a>'
        return html;
    }

    function columnClockInLate(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 2)">' + data.clock_in_late + '</a>'
        return html;
    }

    function columnClockInAbsence(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 3)">' + data.clock_in_absence + '</a>'
        return html;
    }

    function columnClockOutOnTime(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 5)">' + data.clock_out_on_time + '</a>'
        return html;
    }

    function columnClockOutEarly(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 4)">' + data.clock_out_early + '</a>'
        return html;
    }

    function columnFieldCheckIn(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 0, 2)">' + data.field_check_in + '</a>'
        return html;
    }

    function columnPatchCheckIn(value, data)
    {
        var html = '';
        html += '<a onclick="showCheckInLog(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', 0, 3)">' + data.patch_check_in + '</a>'
        return html;
    }

    function columnLeaveTimes(value, data)
    {
        var html = '';
        html += '<a onclick="showFactorList(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', \'leave\')">' + data.leave_times + '</a>'
        return html;
    }

    function columnBusinessTripTimes(value, data)
    {
        var html = '';
        html += '<a onclick="showFactorList(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', \'business_trip\')">' + data.business_trip_times + '</a>'
        return html;
    }

    function columnOvertimeTimes(value, data)
    {
        var html = '';
        html += '<a onclick="showFactorList(\'' + data.oa_contacts_id + '\', \'' + data.start_time + '\',\''+ data.end_time + '\', \'overtime\')">' + data.overtime_times + '</a>'
        return html;
    }

    function showCheckInLog(contactsId, startTime, endTime, resultType, checkInType = 0)
    {
        BJUI.dialog({
            id:'attendance-statistics-check-log',
            url:'/admin/personnel/attendance/statistics-check-in-log',
            title:'考勤日志',
            mask:true,
            width:1080,
            height:720,
            data:{
                'oa_contacts_id':contactsId,
                'start_time':startTime,
                'end_time':endTime,
                'result_type':resultType,
                'check_in_type':checkInType,
            }
        })
    }

    function showFactorList(contactsId, startTime, endTime, type)
    {
        BJUI.dialog({
            id:'attendance-statistics-factor-list',
            url:'/admin/personnel/attendance/factor-list',
            title:'记录',
            mask:true,
            width:1080,
            height:720,
            data:{
                'oa_contacts_id':contactsId,
                'start_time':startTime,
                'end_time':endTime,
                'type':type
            }
        })
    }

    function searchDgAttendanceStatisticsList()
    {
        var data = $.CurrentNavtab.find('.search-form').serializeJson();
        if (data.start_time === '' || data.end_time === '') {
            BJUI.alertmsg('error', '请输入正确的时间');
            return false;
        }
        console.log(data);
        BJUI.ajax('doajax', {
            url:'/admin/personnel/attendance/statistics-count',
            data:data,
            loadingmask:true,
            okCallback:function(data, options){
                $.CurrentNavtab.find('.late-count').text(parseInt(data.clock_in_late) + parseInt(data.clock_in_absence));
                $.CurrentNavtab.find('.early-count').text(parseInt(data.clock_out_early));
            }
        });
        return true;
    }
</script>
